package com.usian.controller;

import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.dtos.WmMaterialDto;
import com.usian.service.WmMaterialService;
import com.usian.wemedia.WmMaterialControllerApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController implements WmMaterialControllerApi {


    @Autowired
    private WmMaterialService wmMaterialService;


    /**
     * 素材图片上传
     *
     * @param file
     * @return
     */
    @Override
    @PostMapping("/upload_picture")
    public ResponseResult uploadPic(MultipartFile file) {
        return wmMaterialService.uploadPic(file);
    }

    /**
     * 素材列表查询
     *
     * @param dto
     * @return
     */
    @RequestMapping("/list")
    @Override
    public ResponseResult findList(@RequestBody WmMaterialDto dto) {
        return wmMaterialService.findList(dto);
    }

    /**
     * 删除素材
     *
     * @param id
     * @return
     */
    @GetMapping("/del_picture/{id}")
    @Override
    public ResponseResult delPic(@PathVariable("id") Integer id) {
        return wmMaterialService.delPic(id);
    }

    /**
     * 收藏
     *
     * @param id
     * @return
     */
    @Override
    @GetMapping("/collect/{id}")
    public ResponseResult shoucang(@PathVariable("id") Integer id) {
        return wmMaterialService.updateStatus(id,(short)1);
    }

    /**
     * 取消收藏
     * @param id
     * @return
     */
    @Override
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancel(@PathVariable("id")Integer id) {
        return wmMaterialService.updateStatus(id,(short)0);
    }


}
